<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
var idchoose=0;
function delmn(id)
{
	if(confirm("Bạn có chắc chắn muốn xóa Menu này?"))
		location.href='{$smarty.const.base_admin}?act=edit-quangcao&do=del&id='+id;
}
var type="";
function listenMessage(msg) {
    SetFileField2(msg.data);
}

if (window.addEventListener) {
    window.addEventListener("message", listenMessage, false);
} else {
    window.attachEvent("onmessage", listenMessage);
}

function show(url,type)
{
	if(type=='smallPicture')
	{
		SetFileField(url);
	}
	else if(type=='contents')
	{
		SetUrl(url);
	}
	else
	{
		SetFileField2(url);
	}
}
function choose(id)
{
	if(id=='smallPicture')
	{
		type='smallPicture';
	}
	else if(id=='contents')
	{
		type='contents';
	}
	else
	{
		type='else';
	}
	window.open("{$smarty.const.base_popup}","popup",'height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes');
}
function SetUrl(fileUrl)
{
	document.getElementById( 'cke_114_textInput' ).value = fileUrl;
	//document.getElementById('smallPicture').innerHTML = "<img src='"+fileUrl+"' width='100px'><input type='hidden' name='smallPicture' value='"+fileUrl+"'></input>";
}
function SetFileField(fileUrl )
{
	document.getElementById('smallPicture').innerHTML = "<img src='"+fileUrl+"' width='100px'><input type='hidden' name='smallPicture' value='"+fileUrl+"'></input>";
}
function SetFileField2(fileUrl )
{
	if(idchoose)
	{
		document.getElementById(idchoose).value=fileUrl;
	}
	/*var inputs = document.getElementsByTagName("input");
	var luu = document.getElementById('imgs').innerHTML;
	var data = [];
	var url=[];
	for (var i = 0; i < inputs.length; i++) {
	if(inputs[i].id.indexOf("image[")==0)
		if(inputs[i].value=="")
		{
			data.push(inputs[i].id,fileUrl);
			fileUrl="";
		}
		else
		{
			data.push(inputs[i].id,inputs[i].value);
		}
	if(inputs[i].id.indexOf("url[")==0)
			url.push(inputs[i].id,inputs[i].value);
	}
	document.getElementById('imgs').innerHTML="";
	var check=0;
	for(var i=0;i<data.length;i++)
	{
		if(data[i+1]=="")
			check=1;
		document.getElementById('imgs').innerHTML += 'Link ảnh: <input type="text" id="'+data[i]+'" name="'+data[i]+'" value="'+data[i+1]+'"> Link website: <input type="text" id="'+url[i]+'" name="'+url[i]+'" value="'+url[i+1]+'"><input type="button" value="Chọn ảnh" onclick="deleteandchoose(\''+data[i]+'\');" /><br>';
		i=i+1;
	}
	if(check==0)
	document.getElementById('imgs').innerHTML +='Link ảnh: <input type="text" id="image['+data.length+']" name="image['+data.length+']" value=""> Link website: <input type="text" id="url['+data.length+']" name="url['+data.length+']" value=""><input type="button" value="Chọn ảnh" onclick="choose(\'chooseimage\');" />';
	*/
}
function deletePicture(id)
{
	document.getElementById(id).innerHTML = "";
}
function deleteandchoose(id)
{
	document.getElementById(id).value="";
	idchoose=id;
	choose('image[0]');
}
</script>

<script src="{$smarty.const.base_includes}ckeditor/ckeditor.js"></script>
 <!-- BEGIN PAGE CONTAINER-->
         <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->   
            <div class="row-fluid">
               <div class="span12">
                   <!-- BEGIN THEME CUSTOMIZER-->
                   <div id="theme-change" class="hidden-phone">
                       <i class="icon-cogs"></i>
                        <span class="settings">
                            <span class="text">Theme Color:</span>
                            <span class="colors">
                                <span class="color-default" data-style="default"></span>
                                <span class="color-green" data-style="green"></span>
                                <span class="color-gray" data-style="gray"></span>
                                <span class="color-purple" data-style="purple"></span>
                                <span class="color-red" data-style="red"></span>
                            </span>
                        </span>
                   </div>
                   <!-- END THEME CUSTOMIZER-->
                  <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                   <h3 class="page-title">
                     {$nameact}
                   </h3>
                   <ul class="breadcrumb">
                       <li>
                           <a href="#">Home</a>
                           <span class="divider">/</span>
                       </li>
                       <li>
                           <a href="#">Data Table</a>
                           <span class="divider">/</span>
                       </li>
                       <li class="active">
                           Dynamic Table
                       </li>
                       <li class="pull-right search-wrap">
                           <form action="http://thevectorlab.net/metrolab/search_result.html" class="hidden-phone">
                               <div class="input-append search-input-area">
                                   <input class="" id="appendedInputButton" type="text">
                                   <button class="btn" type="button"><i class="icon-search"></i> </button>
                               </div>
                           </form>
                       </li>
                   </ul>
                   <!-- END PAGE TITLE & BREADCRUMB-->
               </div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN ADVANCED TABLE widget-->
            <div class="row-fluid">
                <div class="span12">
                <!-- BEGIN EXAMPLE TABLE widget-->
                <div class="widget green">
                    <div class="widget-title">
                        <h4><i class="icon-reorder"></i> {$nameact}</h4>
                            <span class="tools">
                                <a href="javascript:;" class="icon-chevron-down"></a>
                                <a href="javascript:;" class="icon-remove"></a>
                            </span>
                    </div>
					{$msg}<br>
                    <div class="widget-body">
                        <form action="" method="post" class="form-horizontal">
							<div class="control-group">
                                <label class="control-label">Tên Quảng cáo</label>
                                <div class="controls">
                                     <input type="hidden" class="span6" name="id" value="{$data.id}" /><input type="text" class="span6" name="name" value="{$data.name}" />
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Chiều cao</label>
                                <div class="controls">
                                    <input class="span6 " type="text" name="height" value="{$data.height}" />
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Vị trí</label>
                                <div class="controls">
                                   <select name="position">
									{foreach from=$pos item=p}
									<option value="{$p[0]}" {if $data.position eq $p.0} selected=''{/if}>{$p[1]}</option>
									{/foreach}
									</select>
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Thứ tự</label>
                                <div class="controls">
									 <input class="span6 " type="text" name="sort" value="{$data.sort}" />
                                </div>
                            </div>
							<div class="control-group">
                                <label class="control-label">Quảng cáo</label>
                                <div class="controls">
									 <input type="button" value="Thêm quảng cáo" id="newqc" />
								<script>
									$("#newqc").click(function() {
										var inputs = document.getElementsByTagName("input");
										var count=0;
										for (var i = 0; i < inputs.length; i++) {
										if(inputs[i].id.indexOf("image[new][")==0)
											count++;
										}
										$("#imgs").append('Link ảnh: <input type="text" id="image[new]['+count+']"  name="image[new]['+count+']" value=""> Link website: <input type="text" name="url[new]['+count+']" value=""> <input type="button" class="choosebtn" value="Chọn ảnh" onclick="deleteandchoose(\'image[new]['+count+']\');" /><br>');
									});
								</script>
									 <div id="imgs">
										{foreach from=$data.content item=image}
											Link ảnh: <input type="text" id="image[{$image.id}]"  name="image[{$image.id}]" value="{$image.img}"> Link website: <input type="text" name="url[{$image.id}]" value="{$image.url}"> <input type="button" class="choosebtn" id="{$image.id}" value="Chọn ảnh" onclick="deleteandchoose('image[{$image.id}]');" /><br>
										{foreachelse}
											Link ảnh: <input type="text" id="image[new][0]"  name="image[new][0]" value=""> Link website: <input type="text" name="url[new][0]" value=""> <input type="button" class="choosebtn" value="Chọn ảnh" onclick="deleteandchoose('image[new][0]');" /><br>
										{/foreach}
									</div>
                                </div>
                            </div>
			  <div class="form-actions">
                      <button type="submit" name="save" class="btn blue" value='Lưu'><i class=" icon-ok"></i> Lưu</button>
                      <button type="button" class="btn" onclick="delmn({$data.id})"><i class=" icon-remove"></i> Xóa</button>
					  <button type="button" class="btn" onclick="location.href='{$smarty.const.base_admin}?act=quang-cao'"><i class="icon-chevron-left"></i> Trở về</button>
                                </div>
		</form>
                    </div>
                </div>
                <!-- END EXAMPLE TABLE widget-->
                </div>
            </div>

            <!-- END ADVANCED TABLE widget-->
         </div>
         <!-- END PAGE CONTAINER-->
 